package com.ceba.test.base.helper;

import com.ceba.base.helper.SystemCommonHelper;
import com.ceba.cebautils.DateUtil;
import com.ceba.cebautils.StringUtil;
import org.json.JSONObject;

import com.ceba.cebacer.KeyLoaderType;
import com.ceba.test.base.configs.CebaConfig;
import com.ceba.test.base.configs.ServerSignConfig;
import com.ceba.test.base.language.ResourceUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class SystemHelper extends SystemCommonHelper {

	public static String SYSTEM_OUTOFDATE =ResourceUtils.getMessage("MODULES_SYSTEM_EXPIRED_PLEASE_CONTACT_TEST");
	
	public static String SYSTEM_NO_ACTIVE = ResourceUtils.getMessage("MODULES_SYSTEM_NOT_ACTIVATED_PLEASE_CONTACT_CEBA");
	
	/**
	 * 获取软件系列总称
	 * DS
	 * @return
	 */
	public static String getProductName(){
		String systemProductName = CebaConfig.SYSTEM_PRODUCT_NAME;
		return systemProductName;
	}
	
	/**
	 * 获取软件系列小名称
	 * BE
	 * @return
	 */
	public static String getProductLineName(){
		String Version = CebaConfig.USE_VERSION;
		if("3".equals(Version)){
			return ResourceUtils.getMessage("IDS_VERSION_BE");
		}else{
			return ResourceUtils.getMessage("IDS_VERSION_API");
		}
		
	}
	/**
	 * 软件和系列名称
	 * IDS-SE
	 * @return
	 */
	public static String getCompleteProductName(){
		return getProductName();
	}
	/**
	 * 获取系统简写名称--无版本号
	 * IDS-SE 系统
	 * @return
	 */
	public static String getSystemName(){
		return getCompleteProductName()
				+" "+ResourceUtils.getMessage("IDS_SYSTEM");
	}
	
	/*
	 * 软件产品总称--有大版本号
	 * IDS 3.0
	 */
	public static String getSystemVersion(){
		String xVersion = CebaConfig.VERSION;
		xVersion = xVersion.subSequence(0, 1)+ ".0";
		
		xVersion= getProductName()+" "+xVersion;
		return xVersion;
	}
	
	/*
	 * 系统全称--有大版本号
	 * IDS 3.0-BE
	 */
	public static String getSystemBigVersion(){
		String xVersion = CebaConfig.VERSION;
		xVersion = xVersion.subSequence(0, 1)+ ".0";
		xVersion= getProductName()+
				"-"+xVersion;
		return xVersion;
	}
	
	/*
	 * 系统全称--有小版本号
	 * IDS 3.4.5-BE
	 */
	public static String getSystemCompleteVersion(){
		String xVersion = CebaConfig.VERSION;
		xVersion= getProductName()+"-"+xVersion;
		return xVersion;
	}
	
	public static String getSystemSimpleVersion(){
		String Version = CebaConfig.USE_VERSION;
		return Version;
	}
	
	
	/**
	 * 系统可用时间
	 * @return
	 */
	public static String getSystemUseTime(){
		String startTime = CebaConfig.SYSTEM_START_TIME;
		String endTime = CebaConfig.ALLOW_LOGIN_DATE;
		if(!StringUtil.isEmptyString(startTime) && !StringUtil.isEmptyString(endTime)){
			return startTime+ResourceUtils.getMessage("MODULES_TO")+endTime;
		}
		return "无";
	}
	
	/**
	 * 系统到期时间
	 * @return
	 */
	public static String getEndUseTime(){
		return CebaConfig.ALLOW_LOGIN_DATE;
	}
	/*
	 * 可签名份数
	 */
	public static String getAllSignCount(){
		String allSignCount = CebaConfig.REMOTE_NEW_SIGN_COUNT;
		if(!StringUtil.isEmptyString(allSignCount)){
			return allSignCount;
		}
		return ResourceUtils.getMessage("MODILES_NOTHING");
	}
	
	/**
	 * 剩余可签名份数
	 * @return
	 */
	public static String getLeftSignCount(){
		String leftSignCount = CebaConfig.ALLOW_SIGN_NUM;
		if(!StringUtil.isEmptyString(leftSignCount)){
			return leftSignCount;
		}
		return ResourceUtils.getMessage("MODILES_NOTHING");
	}
	
	/**
	 * 系统是否还有签名份数
	 * @return
	 */
	public static boolean isSystemHasLeftSignCount(){
		//判断签名份数
		String leftSignCount = SystemHelper.getLeftSignCount();
		if(ResourceUtils.getMessage("MODILES_NOTHING").equals(leftSignCount)){
			return false;
		}
		int left = Integer.valueOf(leftSignCount);
		if(left <=0){
			return false;
		}
		return true; 
	}
	
	
	/**
	 * 用户是否绑定报告章
	 * @return
	 */
	public static boolean canUserBindStampFlag(){
		return true;
	}
	
	/**
	 * 系统是否过期提醒
	 * @return
	 */
	public static String getSystemOutOfDate() throws ParseException {
		String d=CebaConfig.ALLOW_LOGIN_DATE;
		if(StringUtil.isEmptyString(d)){
			return "";
		}
		int i= DateUtil.getBewteenDay(DateUtil.getNowTime("yyyy-MM-dd"),d);
		DateFormat format = new SimpleDateFormat("yyyyMMdd");
		DateFormat format1 = new SimpleDateFormat("yyyy-MM-dd");
		//现在时间
		int nowTime =Integer.valueOf( DateUtil.getNowTime("yyyyMMdd"));
		//系统到期时间
		int expiryTime =Integer.valueOf(format.format(format1.parse(d)));
		//时间运算
		int sj = expiryTime-nowTime;
		if((i<=29&&i>0) || sj == 0){
			return ResourceUtils.getMessage("MODULES_SYSTEM_ABOUT_DAY_OUT").replace("|",i+1+"");
		}else if(sj<0){
			return ResourceUtils.getMessage("MODULES_SYSTEM_EXPIRED_PLEASE_CONTACT_TEST");
		}
		/*if(i<=29 && i>0){
    		return ResourceUtils.getMessage("MODULES_SYSTEM_ABOUT_DAY_OUT").replace("|",i+1+"");
    	}else if(i == 0){
    		return SYSTEM_OUTOFDATE;
    	}*/
		return "";
		
	}

	/**
	 * 邮件内容配置是否显示1-不显示，2-显示
	 */
	public static boolean isEmailContentShow(){
		return false;
	}
	
	/**
	 * 邮件内容配置是否显示1-不显示，2-显示
	 */
	public static boolean isEnterpriseRegisterShow(){
		if("2".equals(CebaConfig.ENTERPRISEREGISTER_CONFIG_FLAG)){
			return true;
		}
		return false;
	}
	
	/**
	 * 是否开启资质章
	 * @return
	 */
	public static boolean canUseCredentialStampFlag(){
		return true;
	}
	
	/**
	 * QIFENG_FLAG
	 */
	public static boolean canQfengShowFlag(){
		if("true".equals(CebaConfig.QIFENG_FLAG)){
			return true;
		}
		return false;
	}
	/**
	 * 用户是否可以选择资质章
	 * @return
	 */
	public static boolean canChooseCredentialStampFlag(){
		if("true".equals(CebaConfig.SELECT_CREDENTIALS_FLAG) && canUseCredentialStampFlag()){
			return true;
		}else{
			return false;
		}
	}
	
	
	/*
	 * 指纹key启动
	 */
	public static boolean canFingerKeyFlag(){
		if("true".equals(CebaConfig.FINGER_KEY_FLAG) ){
			return true;
		}else{
			return false;
		}
	}
	
	/*
	 * 手写板启动
	 */
	public static boolean canHandBagFlag(){
		if("true".equals(CebaConfig.HAND_BAG_FLAG) ){
			return true;
		}else{
			return false;
		}
	}
	
	/*
	 * 手写签名
	 */
	public static boolean handWriteSignFlag(){
		if("true".equals(CebaConfig.HAND_WRITE_SIGN) ){
			return true;
		}else{
			return false;
		}
	}


	/**
	 * 获取服务器时间
	 * @return
	 */
	public static String getServerTime(){
		return DateUtil.getNowTime(DateUtil.YYYY_MM_DD_HH_MM);
	}
	
	/**
	 * 是否打开通过签名服务器走流程
	 * @return
	 */
	public static boolean canChooseServerSignFlow(){
		return ServerSignConfig.SERVER_SIGN_FLOW ;
	}
	
	
	/**
	 * 获取第三方系统对接,上传文档对应url
	 * @return
	 */
	public static String getThirdUploadFileSystemUrl(){
		return ServerSignConfig.thirdUploadFileSystemUrl;
	}
	
	/**
	 * 是否允许批量签名
	 * 
	 * @return
	 */
	public static  Boolean getBatchSign() {
		if (CebaConfig.BATCH_SIGN.equals("true")) {
			return true;
		}
		return false;
	}

	/**
	 * 是否可使用二维码
	 * @return
	 */
	public static boolean canUseQR() {
		if (CebaConfig.QRCODE.equals("true")) {
			return true;
		}
		return false;
	}
	
	//獲取系統收費類型
	public static String getSystemFeeType(){
		return CebaConfig.SYSTEM_FEE_TYPE;
	}

	/**
	 * 获取公司名称
	 * @return
	 */
	public static String getCompanyName() {
		return CebaConfig.SIGN_COMPANY;
	}
	
	/**
	 * 获取系统是否激活
	 * @return
	 */
	public static String getSignCompanyActiveFlag(){
		return CebaConfig.SING_COMPANY_ACTIVATE_FLAG;
	}
	
	/**
	 * 系统系列版本
	 */
	public static String getUserVision(){
		return CebaConfig.USE_VERSION;
	}
	
	/**
	 * 系统版本号3.5.0
	 */
	public static String getVersion(){
		return CebaConfig.VERSION;
	}
	
	//水印是否限制到PDF的大小
	public static boolean hasNeedLimitSizeFlag(){
		return CebaConfig.needLimitSizeFlag;
	}
	
	//水印是否加到文檔的上层
	public static boolean hasWatermarkOverContent(){
		return "true".equals(CebaConfig.WATERMARK_OVERCONTENT_FLAG)?true:false;
	}

	//二维码服务方式
	public static int qrServiceMethod() {
		return Integer.valueOf(CebaConfig.QRCODE_SERVICE_METHOD);
	}

	public static String getSpecialKeyWorkPrefixSuffix(){
		return CebaConfig.specialKeyWorkPrefixSuffix;
	}
	/*
	 * 系统注册名称
	 */
	public static String getEnterpriseRegisterName(){
		return CebaConfig.SIGN_COMPANY;
	}
	

	/**
	 * 获取最大文件上传10M
	 * @return
	 */
	public static String getFileMaxSize() {
		return CebaConfig.MAX_SIZE;
	}

	/**
	 * 控制签名时关键字没匹配上是否报错 true-不报错 false-报错
	 * @return
	 */
	public static boolean noErrorNotNoramlMatchKey() {
		return CebaConfig.NO_ERROR_NOT_NORMAL_MATCH_KEY;
	}

	/**
	 * 控制Api签名时关键字没匹配上是否报错 true-不报错 false-报错
	 * @return
	 */
	public static boolean noErrorNotNoramlMatchApiKey() {
		return CebaConfig.NO_ERROR_NOT_NORMAL_MATCH_API_KEY;
	}

	/**
	 * 控制Api签名时是否添加二维码 true-允许
	 * @return
	 */
	public static int allowAddQrCodeKey() {
		return CebaConfig.ADD_QR_FOR_API_KEY ? 0:1;
	}

	/**
	 * 用户界面是否展示加二维码
	 * @return
	 */
	public static boolean canShowQrInUserWeb() {
		return CebaConfig.DEFAULT_USER_ALLOW_ADD_QR;
	}

}
